package example.androbot.plugin;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

import com.unicorntoast.android.androbot_libs.utils.AndrobotUtils;

public class SetupActivity extends Activity {

	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        if( !AndrobotUtils.isAndrobotInstalled(this) ) {
			TextView.class.cast(findViewById(R.id.hello)).setText("BotBoNut not installed!");
			return;
        }
        
        startActivityForResult(AndrobotUtils.createRegisterIntent(this,"example",PluginService.class), 0);        
    }
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    	super.onActivityResult(requestCode, resultCode, data);
    	
    	TextView textView = TextView.class.cast(findViewById(R.id.hello));
    	
    	if( resultCode == RESULT_OK ) {
    		textView.setText("example plugin installed!");
    		String secret = AndrobotUtils.secret(data);
			getSharedPreferences("androbot", 0)
    			.edit()
    			.putString("secret", secret)
    			.commit();
    	}
    	else
    		textView.setText("error installing the example plugin");
    }
    
}